package com.study.services;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.study.model.mdao.ProductMapper;
import com.study.model.pojo.Product;

@Service
public class ProductService {
	@Autowired
	ProductMapper pMapper;
	
	//查询所有产品
	public List<Product> findAll(){
		return pMapper.findAll();
	}
	
	//新增产品
	public String addProduct(Product product) {
		String returnString;
		HashMap map=new HashMap<>();
		map.put("proName", product.getProName());
		map.put("proSpe", product.getProSpe());
		int i=pMapper.exist(map);
		if (i>0) {
			returnString="n";
		}else {
			returnString="y";
			pMapper.addProduct(product);
		}
		return returnString;
	}
	
	//删除产品
	public void delProduct(String proId) {
		pMapper.delProduct(proId);
	}
	
	//根据名字查id
	public String findByproName(String proName) {
		return pMapper.findByproName(proName);
	}
	
	/**
	 * 修改产品信息
	 * @param product
	 */
	public void editProduct(Product product) {
		pMapper.editProduct(product);
	}
}
